package com.qf.action;

import com.qf.common.SGHelper;
import com.qf.pojo.entity.TesterMode;
import com.qf.utils.CustomException;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @创建人: fengli
 * @创建时间: 2018/11/9 0009 14:36
 * @包: com.qf.action
 * @描述:
 */
@Controller
@RequestMapping("/app")
public class ModeAction {
    @ResponseBody
    @RequestMapping(value = "/TestPatternQuery")//测试模式配置查询
    public JSONObject TestPatternQuery(HttpServletRequest request, TesterMode testerMode) {
        try {
            return SGHelper.TestPatternQuery(testerMode);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }
    @ResponseBody
    @RequestMapping(value = "/getConfigById")//判断是否有配置(1:存在这条配置信息,0:不存在)administrator
    public JSONObject getConfigById(HttpServletRequest request, TesterMode testerMode) {
        try {
            return SGHelper.getConfigById(testerMode);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }
    @ResponseBody
    @RequestMapping(value = "/cleanBoxIdMap")//判断是否有配置(1:存在这条配置信息,0:不存在)administrator
    public JSONObject cleanBoxIdMap(HttpServletRequest request,String testerId,String testType,String ids) {
        try {
            return SGHelper.cleanBoxIdMap( testerId, testType, ids);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }

    @ResponseBody
    @RequestMapping(value = "/CheckRuleQuery")//校验规则查询
    public JSONObject CheckRuleQuery(HttpServletRequest request, TesterMode testerMode) {
        try {
            return SGHelper.CheckRuleQuery(testerMode);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }

    @ResponseBody
    @RequestMapping(value = "/getDeviceTypeContent")//设备模型属性名查询（deviceInfo已有）
    public JSONObject getDeviceTypeContent(HttpServletRequest request, String deviceTypeID) {
        try {
            return SGHelper.getDeviceTypeContent(deviceTypeID);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }

    @ResponseBody
    @RequestMapping(value = "/TestPatternStore")//测试模式配置存储
    public JSONObject TestPatternStore(HttpServletRequest request, TesterMode testerMode) {
        try {
            return SGHelper.TestPatternStore(testerMode);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }

    @ResponseBody
    @RequestMapping(value = "/CheckRuleStore")//存储校验规则
    public JSONObject CheckRuleStore(HttpServletRequest request, TesterMode testerMode) {
        try {
            return SGHelper.CheckRuleStore(testerMode);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }

    }
}
